import os
#from __future__ import with_statement
from fabric.api import *
from fabric.contrib import *
#from uc_deploy.voa_utilities import *
from uc_deploy.virtualenvwrapper import *
import ConfigParser

'''
this is a working example of a fabfile.py that can be used with uc_deploy.

able to ssh to your local system (apt-get instal openssh-server)

Move the fabfile_example.py to the directory "above" uc_deploy and rename it to be fabfile.py. Then customize items such as the servername, user and so on in the development, staging and deployment sections as required.

In a structure like this:

/home/username/voa/uc_deploy

move and rename fabfile_example.py from here

/home/username/voa/uc_deploy/fabfile_example.py

to here

/home/username/voa/fabfile.py

Usage Example

fab <target_environment> <activity_to_perform>
fab development setup_virtualenvwrappers - Install virtualenvwrappers

to do:
consolidate variables

'''

def _setup_path():
	'''
	...works on at least windows and linux.
	In windows it points to the user's folder
	(the one directly under Documents and Settings, not My Documents)
	In windows, you can choose to care about local versus roaming profiles.
	You can fetch the current user's through PyWin32.

	For example, to ask for the roaming 'Application Data' directory:
	(CSIDL_APPDATA asks for the roaming, CSIDL_LOCAL_APPDATA for the local one)
	(See microsoft references for further CSIDL constants)

	env.home = os.path.expanduser('~')
	'''
	try:
		from win32com.shell import shellcon, shell
		env.home = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

	except ImportError: # quick semi-nasty fallback for non-windows/win32com case
		env.home = os.path.expanduser("~")

	env.workon_path = os.path.join(env.home, env.workon_home)
	# /home/caktus/ + www + development 
	env.root = os.path.join(env.home, 'www', env.environment)
	#				/home/caktus/ + www + development + voa_site
	env.code_root = os.path.join(env.root, env.project)
	#				/home/caktus/ + www + development + env
	env.virtualenv_root = os.path.join(env.root, 'env')
	#					caktus_website.settings developer 
	env.settings = '%(project)s.settings_%(environment)s' % env

def development():
	'''
	setup for developers sytem, usually a local setup.
	'''
	parser = ConfigParser.RawConfigParser()
	parser.read("uc_deploy.cfg")
	env.update(parser.items("Environment"))
	env.hosts = eval(env.hosts)
	_setup_path()

def setup_virtualenvwrappers():
	require('root', provided_by=('development','staging', 'production'))
	install_virtualenvwrapper()
	conf_wrapper()
	export_workon_home()
	create_workon_home()
	source_virtualenvwrapper()
